export const phoneReg = phoneNumber => {
  const reg = /^1[3456789]\d{9}$/
  return reg.test(phoneNumber)
}

export const onlyNumber = number => {
  const reg = /^\d+(\.[0-9]+)?$/
  return reg.test(number)
}

//整数0++
export const isInteger = text => {
  const reg = /^[+]?\d*$/
  return reg.test(text)
}

//小数点后两位
export const twoDecimalPoint = number => {
  const reg = /^(\d+)(.\d{0,2})?$/
  return reg.test(number)
}

//整数 1+++
export function moreThanOneInteger(string) {
  const reg = /^(1|[1-9][0-9]*)$/
  return reg.test(string)
}

export function formattedAmount(amount) {
  if (amount === null || isNaN(amount)) {
    return '--'
  }

  if (!isNaN(amount)) {
    //return amount.toFixed(2)
    //let fixedAmount = amount.toFixed(2)
    amount = amount.toString()
    const index = amount.indexOf('.')
    if (index !== -1) {
      amount = amount.substring(0, 2 + index + 1)
    } else {
      amount = amount.substring(0)
    }
    let fixedAmount = parseFloat(amount).toFixed(2)

    const parts = fixedAmount.toString().split('.')
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
    return parts.join('.')
  }

  //截取后保留两位小数
}
